package org.xiaodongwei.jvm.op;

import org.xiaodongwei.jvm.exe.JVMStack;
import tech.medivh.classpy.classfile.bytecode.Instruction;
import tech.medivh.classpy.classfile.jvm.Opcode;

public class IConstOpCodeExecute extends OpCodeExecute{

    public IConstOpCodeExecute(Opcode opcode, JVMStack jvmStack) {
        this.opCode = opcode;
        this.jvmStack = jvmStack;
    }

    @Override
    public void execute(Instruction instruction) {
        switch (this.opCode) {
            case iconst_0 -> {
                jvmStack.peek().getOperateStack().push(0);
            }
            case iconst_1 -> {
                jvmStack.peek().getOperateStack().push(1);
            }
            case iconst_2 -> {
                jvmStack.peek().getOperateStack().push(2);
            }
            case iconst_3 -> {
                jvmStack.peek().getOperateStack().push(3);
            }
            case iconst_4 -> {
                jvmStack.peek().getOperateStack().push(4);
            }
            case iconst_5 -> {
                jvmStack.peek().getOperateStack().push(5);
            }
            default -> {

            }
        }
    }
}
